
$(function() {
        var navH = $(".cpLine-rt").offset().top;
        var footerH = $('.ryCon').offset().top;
        $(window).scroll(function() {
                var scroH = $(this).scrollTop();
                var scroHs = $(this).scrollTop() + $(this).height() + 60;
                var mtop = $(document).height() - $('.footerH').height() - $(".cpLine-rt").height();
                var mright = ($(document).width() - 1200) / 2;
                if (scroH >= navH && scroHs <= footerH) {
                        $('.lineNav_top1').css('top', 'auto');
                        $('.lineNav_top').css('right', mright);
                        $(".cpLine-rt").removeClass("lineNav_top1");
                        $(".cpLine-rt").addClass("lineNav_top");
                } else if (scroH < navH) {
                        $('.lineNav_top1').css('top', 'auto');
                        $(".cpLine-rt").removeClass("lineNav_top");
                        $(".cpLine-rt").removeClass("lineNav_top1");
                } else if (scroHs > footerH) {
                        $(".cpLine-rt").removeClass("lineNav_top");
                        $('.lineNav_top1').css('right', mright);
                        $('.lineNav_top1').css('top', mtop);
                        $(".cpLine-rt").addClass("lineNav_top1");
                }
        });


        //滚动导航
        var fobj = $('.cpLine_tit').eq(0);
        var fpos = fobj.offset();
        $(window).scroll(function() {
                checkPos(fobj, fpos);
        });
        $(".calendar").hover(function() {
                $(this).addClass("helloBox");
        }, function() {
                $(this).removeClass("helloBox");
        });
        //滚动导航 2


        $('#LineNav').onePageNav();

        $('#LeftNav').onePageNav();
        //行程左侧固定头
        var LeftNavHeight = $(".jour-item-con").offset().top;
        var RightNeirong = $(".jour-item-con").offset().top;
        var RightNeirongHeight = $(".jour-item-con").height();
        var RgihtNeirongNum = RightNeirong + RightNeirongHeight - 200;
        $(window).scroll(function() {
                var scroH2 = $(this).scrollTop();
                if (scroH2 >= LeftNavHeight) {
                        $("#LeftNav").css({"position": "fixed", "top": 80}).show();
                } else if (scroH2 < LeftNavHeight) {
                        $("#LeftNav").css({"position": "static"}).hide();
                }
                if (scroH2 >= RgihtNeirongNum) {
                        $("#LeftNav").css({"position": "static"}).hide();
                }
        });


        //加入收藏
        $(".addCollection").click(function() {
                var id = $(this).attr("id");
                $.ajax({
                        type: "POST",
                        url: "/line/collect",
                        data: {id: id},
                        dataType: "json",
                        success: function(data) {
                                if (data.msg == "未登录") {
                                        window.location.href = data.url;
                                }
                                if (data.code > 0) {
                                        $(".bot_con_bg").removeClass("errors").addClass("succes");
                                        $(".zhedang").fadeIn(250);
                                        $(".duifou").fadeIn(300);
                                        $(".bot_con_txt").html(data.msg);
                                }
                                if (data.code == 0 && data.msg != "未登录") {
                                        $(".bot_con_bg").removeClass("succes").addClass("errors");
                                        $(".zhedang").fadeIn(350);
                                        $(".duifou").fadeIn(400);
                                        $(".bot_con_txt").html("对不起，" + "<em>" + data.info + "</em>" + "请到会员中心查看！");
                                }
                        }
                });
        });

        //关闭窗口按钮
        $(".duifou").on('click', '#cls', function() {
                $(".duifou").fadeOut(250);
                $(".zhedang").fadeOut(300);
        });
        //select美化
        $("#vehicle_id").selectbox({
                speed: 250
        });
});

function ajaxChangePrice(price_id, key) {
        $("#vehicle_id").selectbox('detach');
        var price_id1 = price_id;
        var key1 = key;
        $.ajax({
                url: "/Line/PriceCheck",
                data: {
                        tours_id: lineId,
                        price_id: price_id1
                },
                dataType: "json",
                type: "post",
                beforeSend: function() {
                        $("#datatype_" + key1).addClass("selected").siblings().removeClass('selected');
                        $(".zhedang").fadeIn(250);
                        var top = $(window).height() / 2 - 40;
                        var width = $(document).width() / 2 - 40;
                        $("#genxin").css({top: top, left: width}).show();
                },
                success: function(data) {
                        if (data !== '') {
                                $("#genxin").fadeOut(250);
                                $(".zhedang").fadeOut(300);
                                $('#price_all').html(data.sprice);
                                var vehicle_id = $("#vehicle_id");
                                $("#vehicle_id").empty();
                                for (var p in data) {
                                        if (p === 'sprice' || p === 'undefined') {
                                        } else {
                                                var option = $("<option>").val(p).text(data[p]);
                                                vehicle_id.append(option);
                                        }
                                }


                                $("#vehicle_id").selectbox({
                                        speed: 250
                                });
                        } else {
                                $("#genxin").html('!加载错误,<br/>请尝试刷新页面');
                        }
                }
        });
}

function checkPos(fobj, fpos) {
        if ('undefined' == typeof (document.body.style.maxHeight)) {
                var scTop = $(window).scrollTop();
                scTop > fpos.top ? fobj.css({'position': 'absolute', 'z-index': 3, 'top': scTop - fpos.top}) : fobj.attr('style', '');
        } else {
                ($(window).scrollTop() > fpos.top) ? fobj.css({'position': 'fixed', 'z-index': 3, 'top': 0}) : fobj.css({'position': 'static'});
        }
}


//咨询提交成功后关闭按钮
function counselClose() {
        $("#counsel").hide();
        $("#collect").hide();
}

//咨询数据验证
function check_data() {
        var phone = $('#phone').val();
        var content = $("#content").val();
        var vertify = $("#txt_yzm").val();
        if (content.length < 5) {
                alert('问题内容不能小于5个字符!');
                return false;
        }
        if (content.length > 300) {
                alert('字符超过限制！');
                return false;
        }
        if (!(/^1[3|5|4|8][0-9]\d{4,8}$/.test(phone))) {
                alert("不是完整的11位手机号或者不正确的手机号");
                return false;
        }
        if (vertify == null || vertify == '') {
                alert('验证码不能为空!');
                return false;
        }
        return true;
}
//咨询数据提交
function submit_data() {
        var phone = $("#phone").val();
        var content = $("#content").val();
        var verify = $("#txt_yzm").val();
        if (check_data()) {
                var data = {phone: phone, content: content, verify: verify, line_id: lineId};
                if (phone.length > 0 && phone.length == 11) {
                        data.phone = phone;
                }
                $.ajax({
                        type: "POST",
                        url: "/tours/line/counsel_add",
                        data: data,
                        dataType: "json",
                        success: function(data) {
                                if (data.msg === "uidnull") {
                                        window.location.href = data.url;
                                } else if (data.msg === "potsucc") {
                                        $("#content").val('');
                                        $("#phone").val('');
                                        $("#txt_yzm").val('');

                                        var top = $(window).scrollTop() + $(window).height() / 2 - 100;
                                        var width = $(document).width() / 2 - 200;
                                        $("#counsel").css({top: top, left: width}).show();
                                } else {
                                        alert(data.msg);
                                }
                        }
                });
        }
}
//用户点评
function dpClick() {
        var user_id = $.cookie('uid');
        var top = $(window).scrollTop() + $(window).height() / 2 - 100;

        var width = $(document).width() / 2 - 200;
        if ((user_id == null) || (user_id == '')) {
                $("#zxdp_error").css({top: top, left: width}).show();
                return false;
        }
        /*
         $.get("line/checks", {uid: user_id, tours_id: lineId}, function (data) {
         console.log(data);
         if (data.status != 9) {
         $("#zxdp_error").css({top: top, left: width}).show();
         } else {
         window.location.href = "/user/addcomment/id/" + data.order_id + "";
         }
         });
         */
        return false;

}
function dpClose() {
        $("#zxdp_error").hide();
}

